﻿
/***********************************************/
//当前页面实例
var currentPage;
//控件集合实例
var controlsCollection;
//命名空间
var UserList;

$(document).ready(function () {
    var collection = [
        New(ASPxRFTextBox, ['txtRealname', ['GroupA'], 'Realname']),
        New(ASPxRFTextBox, ['txtDeptName', ['GroupA'], 'DeptName']),
        New(ASPxRFTextBox, ['txtUsername', ['GroupA'], 'Username']),
        New(ASPxRFTextBox, ['txtEmail', ['GroupA'], 'Email']),
        New(ASPxRFSpinEdit, ['seMobilePhone', ['GroupA'], 'MobilePhone']),
        New(ASPxRFRadioButtonList, ['rblIsApproved', ['GroupA'], { valueField: 'IsApproved'}]),
        New(ASPxRFRadioButtonList, ['rblIsLockedOut', ['GroupA'], { valueField: 'IsLockedOut'}]),
        New(ASPxRFDateEdit, ['deCreateDate', ['GroupA'], 'CreateDate', 'yyyy-MM-dd HH:mm:ss'])
    ];
    controlsCollection = New(RapidForm, [collection]);

    //页面命名空间简写
    UserList = SGDemo.Permission.UserList;

    //声明页面信息
    var navigationInfo = { moduleValue: 'Permission', itemValue: 'UserItem', itemName: '用户明细' };
    currentPage = New(RFPage, [menuHeader, gvwList, ['btnEdit','btnView'], ['btnBulkEdit', 'btnDelete', 'btnAudit'], null, navigationInfo]);
    currentPage.firstLoad();
});

/***********************************************/
//审核通过
var doAuditSuccess = function () {
    $.messager.confirm('确认提示', '确认审核通过?', function (result) {
        if (result) {
            //获取选择记录Keyids
            var keyids = gvwList.GetSelectedKeysOnPage().join('_');
            //调用审核通过方法
            UserList.AuditSuccess(keyids, function (result) {
                if (result.value) {
                    gvwList.PerformCallback();
                    $.messager.show({
                        title: '信息提示',
                        msg: '审核通过成功',
                        showType: 'slide'
                    });

                } else {
                    $.messager.show({
                        title: '信息提示',
                        msg: '审核通过失败！',
                        showType: 'slide'
                    });
                }
            });
        }
    });
}
//取消审核
var doAuditFailure = function () {
    $.messager.confirm('确认提示', '确认取消审核吗?', function (result) {
        if (result) {
            //获取选择记录Keyids
            var keyids = gvwList.GetSelectedKeysOnPage().join('_');
            //调用审核通过方法
            UserList.AuditFailure(keyids, function (result) {
                if (result.value) {
                    gvwList.PerformCallback();
                    $.messager.show({
                        title: '信息提示',
                        msg: '取消审核操作成功',
                        showType: 'slide'
                    });

                } else {
                    $.messager.show({
                        title: '信息提示',
                        msg: '取消审核操作失败！',
                        showType: 'slide'
                    });
                }
            });
        }
    });
}
//删除
var doBulkDelete = function () {
    $.messager.confirm('确认提示', '确认删除吗?', function (result) {
        if (result) {
            //获取选择记录Keyids
            var keyids = gvwList.GetSelectedKeysOnPage().join('_');
            //调用删除方法
            UserList.BulkDelete(keyids, function (result) {
                if (result.value) {
                    gvwList.PerformCallback();
                    $.messager.show({
                        title: '信息提示',
                        msg: '删除成功！',
                        showType: 'slide'
                    });

                } else {
                    $.messager.show({
                        title: '信息提示',
                        msg: '删除失败！',
                        showType: 'slide'
                    });
                }
            });
        }
    });
}

//查找提交
function doSubmittedToSearch(s, e) {
    doListAll();
    $('#hfFilterCondition').val(controlsCollection.getQueryString('GroupA'));
    gvwList.PerformCallback();
}
//查找重置
var doResetToSearch = function (s, e) {
    controlsCollection.reset('GroupA');
}
//批量更新
var doBulkEdit = function () {
    Shadowbox.open({
        content: '../../../Views/Permission/Popup/BulkEditUsers.aspx',
        player: 'iframe',
        title: '批量更新用户',
        height: 140,
        width: 720
    });
}

//固定查询
var doFixedQueryToRun = function (arg) {
    switch (arg) {
        case 'A': $('#hfFilterCondition').val('IsApproved=true'); break;
        case 'B': $('#hfFilterCondition').val('IsLockedOut=true'); break;
        case 'C': $('#hfFilterCondition').val('Email=@163.com'); break;
        case 'D': $('#hfFilterCondition').val('Realname=李'); break;
        case 'E': $('#hfFilterCondition').val('CreateName=admin'); break;
        default: return;
    }
    doListAll();
    gvwList.PerformCallback();
}

/***********************************************/
//GridView选中全部或者取消选中全部
var doSelectOrUnselectAll = function (s, e) {
    gvwList.SelectAllRowsOnPage(s.GetChecked());
}
//GridView选择事件
function doSelectionChanged() {
    currentPage.selectionChanged();
}
//GridView双击行打开明细
function doRowDblClick(s, e) {
    currentPage.rowDblClick(s, e);
}
//明细
var doView = function () {
    currentPage.toView();
}
//新增
var doAdd = function () {
    currentPage.toAdd();
}
//编辑
var doEdit = function () {
    currentPage.toEdit();
}
//固定查询
var doFixedQuery = function () {
    doDisplay('fixedquery');
    currentPage.toSearch();
}
//查找
var doSearch = function () {
    doDisplay('search');
    txtUsername.Focus();
    currentPage.toSearch();
}
//显示所有
var doListAll = function () {
    doDisplay('listall');
    currentPage.toListAll();
}
//刷新
var doRefresh = function () {
    $('#hfFilterCondition').val(' ')
    gvwList.PerformCallback();
}
//导出数据
var doExport = function () {
    pcExport.Show();
}
//导入数据
var doImport = function () {
    Shadowbox.open({
        content: '../../../Views/Permission/Popup/ImportUserDate.aspx',
        player: 'iframe',
        title: '导入用户数据',
        height: 340,
        width: 720
    });
}

//打印
var doPrint = function () {
    window.print();
}
//关闭导出数据窗口
var doCloseToExport = function () {
    pcExport.Hide();
}

//帮助
var doHelp = function () {
    window.open('../../../Help.aspx', 'Help'); // 打开一个标签页
}
//添加快捷方式
var doSetShortcut = function () {
    SGDemo.Permission.UserList.SaveFastAdd(function (result) {
        if (result.value) {
            $.messager.show({
                title: '信息提示',
                msg: '添加快捷方式成功！',
                showType: 'slide'
            });

        } else {
            $.messager.show({
                title: '信息提示',
                msg: '添加快捷方式失败！',
                showType: 'slide'
            });
        }

    });
}